/**
 * @desc 任务记录
 */

'use strict'

const MODEL_NAME = 'todo'
const COLLECTION_NAME = 'todos'
const USER_MODEL_NAME = 'user'
const PROJECT_MODEL_NAME = 'project'

module.exports = app => {
  const mongoose = app.mongoose
  const Schema = mongoose.Schema

  const TodoSchema = new Schema({
    pid: { type: Schema.Types.ObjectId, ref: PROJECT_MODEL_NAME, required: true }, // 项目id
    owner: { type: Schema.Types.ObjectId, ref: USER_MODEL_NAME, required: true }, // 所有者id

    title: { type: String, default: '' },
    content: { type: String, default: '' },
    status: { type: String, enum: ['done', 'doing'], default: 'doing' },

    createdAt: { type: Date, default: Date.now },
    updatedAt: { type: Date, default: Date.now },
  })

  return mongoose.model(MODEL_NAME, TodoSchema, COLLECTION_NAME)
}
